const tools = {};
/**
 * treeDataFilter 递归树结构数据赋值（异步） 递归效率最高 存在堆栈溢出问题
 * @param {array} params.data 树形结构数据
 * @param {function} params.filter 回调函数
 * @level level 当前节点的层级
 */
tools.treeDataFilter = (params, level = 0) => {
    let data = params.data
    _.forEach(data, (v) => {
        const result = params.filter(v, level)
        //终止跳出循环递归。
        if (typeof result === 'boolean' && !result) {
            throw new Error('')
        }
        if (Array.isArray(v.children) && v.children.length) {
            tools.treeDataFilter({
                data: v.children,
                filter: params.filter,
            }, level + 1)
        }
    })
}

/**
 * 获取32位uuid
 * @returns {string}
 */
tools.getUuid=()=>{
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        let r = Math.random() * 16 | 0,
            v = c === 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}


export default tools;
